<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>linclass.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>[y,dfce]</span>=<span class=defun_name>linclass</span>(<span class=defun_in>&nbsp;X,&nbsp;model</span>)<br>
<span class=h1>%&nbsp;LINCLASS&nbsp;Linear&nbsp;classifier.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;[y,dfce]&nbsp;=&nbsp;linclass(&nbsp;X,&nbsp;model)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;This&nbsp;function&nbsp;classifies&nbsp;input&nbsp;data&nbsp;X&nbsp;using&nbsp;linear</span><br>
<span class=help>%&nbsp;&nbsp;discriminant&nbsp;function:</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;y(i)&nbsp;=&nbsp;argmax&nbsp;W(:,y)'*X(:,i)&nbsp;+&nbsp;b(y)</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;where&nbsp;parameters&nbsp;W&nbsp;[dim&nbsp;x&nbsp;nfun]&nbsp;and&nbsp;b&nbsp;[1&nbsp;x&nbsp;nfun]&nbsp;are&nbsp;given&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;in&nbsp;model&nbsp;and&nbsp;nfun&nbsp;is&nbsp;number&nbsp;of&nbsp;discriminant&nbsp;functions.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;In&nbsp;the&nbsp;binary&nbsp;case&nbsp;(nfun=1)&nbsp;the&nbsp;classification&nbsp;rule&nbsp;is&nbsp;following</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;y(i)&nbsp;=&nbsp;1&nbsp;if&nbsp;W'*X(:,i)&nbsp;+&nbsp;b&nbsp;&gt;=&nbsp;0</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;if&nbsp;W'*X(:,i)&nbsp;+&nbsp;b&nbsp;&lt;&nbsp;0</span><br>
<span class=help>%&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;where&nbsp;W&nbsp;[dim&nbsp;x&nbsp;1],&nbsp;b&nbsp;[1x1]&nbsp;are&nbsp;parameters&nbsp;given&nbsp;in&nbsp;model.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Input:</span></span><br>
<span class=help>%&nbsp;&nbsp;X&nbsp;[dim&nbsp;x&nbsp;num_data]&nbsp;Data&nbsp;to&nbsp;be&nbsp;classified.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;[struct]&nbsp;Parameters&nbsp;of&nbsp;linear&nbsp;classifier:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.W&nbsp;[dim&nbsp;x&nbsp;nfun]&nbsp;Linear&nbsp;term.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.b&nbsp;[nfun&nbsp;x&nbsp;1]&nbsp;Bias.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Output:</span></span><br>
<span class=help>%&nbsp;&nbsp;y&nbsp;[1&nbsp;x&nbsp;num_data]&nbsp;Predicted&nbsp;labels.</span><br>
<span class=help>%&nbsp;&nbsp;dfce&nbsp;[nfun&nbsp;x&nbsp;num_data]&nbsp;Values&nbsp;of&nbsp;discriminat&nbsp;function.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Examples:</span></span><br>
<span class=help>%&nbsp;&nbsp;trn&nbsp;=&nbsp;load('riply_trn');</span><br>
<span class=help>%&nbsp;&nbsp;tst&nbsp;=&nbsp;load('riply_tst');</span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;=&nbsp;fld(&nbsp;trn&nbsp;);</span><br>
<span class=help>%&nbsp;&nbsp;ypred&nbsp;=&nbsp;linclass(&nbsp;tst.X,&nbsp;model&nbsp;);</span><br>
<span class=help>%&nbsp;&nbsp;cerror(&nbsp;ypred,&nbsp;tst.y&nbsp;)</span><br>
<span class=help>%&nbsp;&nbsp;figure;&nbsp;ppatterns(&nbsp;trn&nbsp;);&nbsp;pline(&nbsp;model&nbsp;);</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;PERCEPTRON,&nbsp;MPERCEPTRON,&nbsp;FLD,&nbsp;ANDERSON.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;2-may-2004,&nbsp;VF</span><br>
<br>
<hr>
<span class=comment>%&nbsp;allow&nbsp;model&nbsp;to&nbsp;be&nbsp;gievn&nbsp;as&nbsp;a&nbsp;cell</span><br>
model&nbsp;=&nbsp;c2s(model);<br>
<br>
[dim,&nbsp;num_data]&nbsp;=&nbsp;size(X);<br>
<br>
nfun&nbsp;=&nbsp;size(model.W,2);<br>
<br>
<span class=keyword>if</span>&nbsp;nfun&nbsp;==&nbsp;1,<br>
&nbsp;&nbsp;<span class=comment>%&nbsp;binary&nbsp;case</span><br>
&nbsp;&nbsp;dfce&nbsp;=&nbsp;model.W'*X&nbsp;+&nbsp;model.b;<br>
&nbsp;&nbsp;y&nbsp;=&nbsp;ones(1,num_data);<br>
&nbsp;&nbsp;y(find(dfce&nbsp;&lt;&nbsp;0))&nbsp;=&nbsp;2;<br>
<span class=keyword>else</span><br>
&nbsp;&nbsp;<span class=comment>%&nbsp;multi-class&nbsp;case&nbsp;</span><br>
&nbsp;&nbsp;dfce&nbsp;=&nbsp;model.W'*X&nbsp;+&nbsp;model.b(:)*ones(1,num_data);<br>
&nbsp;&nbsp;[dummy,y]&nbsp;=&nbsp;max(&nbsp;dfce&nbsp;);<br>
<span class=keyword>end</span><br>
<br>
<span class=jump>return</span>;<br>
</code>
